package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class AddressBook here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class AddressBook
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> person;
    private static AddressBook instance;
 
/**
 * *******************SINGLETON PATTERN***************************
 */    
    /**
     * Constructor for objects of class AddressBook
     */
    private AddressBook()
    {
        
        // initialise instance variables
        person = new ArrayList<Person>();
    }
    
    public static AddressBook getInstance() // calls the constructor
    {
        if( null == instance )
        {
            instance = new AddressBook();
        }
        
        return instance;
    }
/**
 * *******************************************************************
 */
    
    public void setPerson(String id, String name, String address, String postalCode, String city, String phone)
    {
        
        
        person.add( new Person (id, name, address, postalCode, city, phone) ); // Set person by this method
    }
   
    public ArrayList<Person> getPerson()   
    {
        return person;
    }
    
    /**
     * Deletes a person with a ginven ID.
     */
    public void deletePerson(String id) //delete person by ID
    {
      int index = person.indexOf( findPerson(id) ) ;
      person.remove(index);
                       
    }
    
    /**
     * Finds a person with a given ID.
     */
    public Person findPerson(String id)
    {
        
           
        for(int index = 0; index < person.size(); index++)
        { 
            if( person.get(index).getID().equals(id) )
            {
                
                return person.get(index);
            }
        }
        
        return null;
    }
    
    /**
     * Edits a person.
     */
    
   
    
    public void editPerson(Person person, String name, String address, String postalCode, String city, String phone)
    {
        person.setName(name);
        person.setAddress(address);
        person.setPostalCode(postalCode);
        person.setCity(city);
        person.setPhone(phone);
    }
        
        
    
    
    
     
}
